package com.luzhikun.procinceAjax.db;

import java.sql.*;

/**
 * @Author Rookie Coder
 * @Description 数据库连接工具类
 * @Date
 **/
public class JDBCUtil {

    /*
     * @Author liu-miss
     * @Description 获取连接
     * @Date 16:17 2021/5/9
     * @Param []
     * @return java.sql.Connection
     **/
    public Connection getConnection() throws SQLException, ClassNotFoundException {
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://localhost:3306/springdb";
        String user="root";
        String password="140489lu";
        return DriverManager.getConnection(url,user,password);
    }

    /*
     * @Author liu-miss
     * @Description 关闭数据库资源
     * @Date 16:21 2021/5/9
     * @Param [conn, pst, rs]
     * @return void
     **/
    public void closeAll(Connection conn, PreparedStatement pst, ResultSet rs) throws SQLException {
        if (conn!=null){
            conn.close();
        }
        if (pst!=null){
            pst.close();
        }
        if (rs!=null){
            rs.close();
        }

    }

}
